import dayjs from "dayjs";

export function hint(msg = "成功", type = "success", time = 1000) {
  ElMessage({
    showClose: true,
    message: msg,
    type: type,
    duration: time,
  });
}

export function confirm(msg = "你确定？", type = "success") {
  return ElMessageBox.confirm(msg, "", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: type,
  });
}

export function time(val = "2022-12-12 21:03:11") {
  const timeD = dayjs(dayjs().format()).unix() - dayjs(val).unix();
  if (timeD >= 3600 * 24 * 3) {
    return "三天前";
  } else if (timeD >= 3600 * 24) {
    return "一天前";
  } else if (timeD < 3600 * 24 && timeD > 0) {
    let h = parseInt(timeD / 3600);
    let m = parseInt((timeD % 3600) / 60);
    let s = parseInt(timeD % 60);

    return `${h > 9 ? h : "0" + h}:${m > 9 ? m : "0" + m}:${
      s > 9 ? s : "0" + s
    }`;
  } else {
    return "请输入正确的时间";
  }
}



export function newTime(val='YYYY-MM-DD') {
  return dayjs().format(val)
}